<?php
	
class LoginView {

	public $username = "username";
	public $password = "password";
	private $LoginButton = "loginbutton";
	private $LogOutButton = "logoutbutton";
	private $Remember = "remember";
	
	
	//Funktion för att kolla om rememberme är checked.
	public function rememberMe(){
	    if(isset($_GET[$this->Remember])){
	        return true;
	    }
	    return false;
    }
	
	public function DoLoginBox() {
		//returnerar login rutan ..
		$xhtml = "<h2>Login Controller</h2> 
		<form method='get' class='login'> 
	    	<fieldset >
	    		User name: <input type='text' name='$this->username' /><br />
        		Password.: <input type='password' name='$this->password' /><br />
	       
	   			<input type='submit' name='$this->LoginButton' value='Login' style='float:left;' />
	   				<input type='checkbox' style='margin-left: 22px;' name='$this->Remember' value='remember' /> Remember me
	   	</form>"; 
		return $xhtml;
  	}
	
	public function DoLogoutBox() {
		//returnerar en logga ut knapp ..
	    return "
	    	<form name='input' method='get'> 
	    		</br><input type='submit' name='$this->LogOutButton' value='LogOut' style='float: left;' />
	    	</form>
	    </fieldset>";
	    
  	}
  	//Funktion för att skapa cookie.
	public function createCookie($username, $password)
    {
        setcookie($this->username, $username, time()+3600*24*7);
        setcookie($this->password, $password, time()+3600*24*7);
    }

    public function isCookieSet(){
	    if(isset($_COOKIE[$this->username]) && isset($_COOKIE[$this->password])){
	        return true;
	    }
	    else{
	        return false;
	    }
    }
    
	// Tar bort cookie vid utloggning.
    public function removeCookie(){
		setcookie($this->username, '', time()-3600*24*7);
			unset($_COOKIE[$this->username]);
		setcookie($this->password, '', time()-3600*24*7);
			unset($_COOKIE[$this->password]);
    }

		

  	public function GetUserName(){
 
       if (isset( $_GET[$this->username]) == true) {
      		return $_GET[$this->username];
		}
		return null;
        
  	}
 
  	public function GetPassword(){
        if (isset( $_GET[$this->password]) == true) {
      		return $_GET[$this->password];
  		}
		return null;
  	}
 
  	public function TriedToLogIn(){
        if (isset( $_GET[$this->LoginButton]) == true) {
      		return true;
    	}
        return false;
	}
	
	public function TriedToLogOut(){
        if (isset( $_GET[$this->LogOutButton]) == true) {        	
      		return true;
    	}
	    return false;
  	}
  	
	public function LoggedInMessage(){
		
  		// $xhtml = '
			 // <form enctype="multipart/form-data" action="upload_file.php" method="POST">
			 // Välj en fil: <input name="uploaded" type="file" /><br />
			 // <input type="submit" value="Ladda upp" />
			 // </form> <hr />' . '<a href="uploads/">Visa uppladdningar</a>' ;
			 
			 $uname = $this->GetUserName();
		$xhtml = '<br/>Välkommen <b>' . $uname .'</b>';
						
		return $xhtml;

	}
}
